<?PHP
defined('_XR_EXEC') or die();
/**
 * 控制器处理类 
 */
class news_controller extends controller{
	var $pagelist = 20;
	function __construct(){
		parent::__construct();
	}
	
	public function index__(){
	  $pentype_id = '1';
		$_GET=format::addslash_deep($_GET);
		# 本身类别
		$db = factory::getDBO();
		# 总数
		$where = ' where a.pentype_id = "'.$pentype_id.'" and a.deleted=0 and a.publishs=1 ' ;
		$all_num = $db->loadresult('select count(a.id) from `t_pen` a '.$where);
		# 当前页
		$page = 1;
		if(isset($_GET['page'])) $page = intval($_GET['page']);
		# 对象
		$config=array(
			'list_num'=>$this->pagelist,
			'all_num'=>$all_num,
			'now_page'=>$page,
			'url'=>url::build(R::singleton()->gets['controller'],R::singleton()->gets['action']).'?',
			'classname'=>'pageslist'
		);
		$pageo = new mlpage($config);
		$page_html = $pageo->get_page();
		# 得到详细数据
		$rs_list = $db->loadassoclist('
			select 
			a.id,
			a.title,
			a.create_date
			from `t_pen` a 
		'.$where.' order by a.id desc '.$pageo->get_limit()); 
		$this->assign('rs_list',$rs_list);
		$this->assign('page_html',$page_html);
		$this->assign('now_page',$pageo->now_page);  
		$this->assign('all_page',$pageo->all_page);  
	}
  
	public function show__(){
		$_GET=format::addslash_deep($_GET);
		$id = intval($_GET['id']);
		$db = factory::getDBO();
		$rs = $db->loadassoc('select a.* from `t_pen` a  where deleted=0 and a.publishs=1 and a.pentype_id=1 and a.id="'.$id.'" ');
		if(!$rs){
			url::jump('/home/index');
		}
		$this->assign('rs',$rs);
		/* 计数 */
		$db->query('update `t_pen` set showcount=showcount+1  where id="'.$id.'"');
	}
   
}
?>